ValidatedEntityAttribute

A validated Pairing of an EntityAttribute and a corresponding EntityAttributeModifier

ValidatedEntityAttribute has a private constructor, use Builder to create one

Author

fzzyhmstrs

Since

0.3.1

See also

Samples

import com.google.common.collect.ArrayListMultimap
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedEntityAttribute
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIngredient
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedTagKey
import net.minecraft.entity.attribute.EntityAttribute
import net.minecraft.entity.attribute.EntityAttributeModifier
import net.minecraft.recipe.Ingredient
import net.minecraft.registry.tag.BlockTags
import net.minecraft.registry.tag.ItemTags
import net.minecraft.util.Identifier

fun main() { 
   //sampleStart 
   // a Validated entity attrbute/entity attribute modifier pair
// the builder does not accept an EntityAttribute because it needs to serialize them,
// and the attribute might not be available at serialization time in the registry
// lockAttribute lets you constrain the attribute to the one chosen in the builder (Max Health in this case_
val exampleValidatedAttribute = ValidatedEntityAttribute.Builder("generic.max_health", true)
    // supply a UUID and name, otherwise generic ones will be used for you
    .uuid("f68e98a2-0599-11ef-9262-0242ac120002")
    .name("My Example ValidatedEntityAttribute")
    //set amount, and optionally provide a range restriction
    .amount(1.0, 0.0, 8.0)
    //set the operation for the modifier, and optionally lock the modifier to the operation chosen
    .operation(EntityAttributeModifier.Operation.ADD_VALUE, true)
    //build! gets you a ValidatedEntity Attribute
    .build()

//easily add to an attribute map in e.g. Item#getAttributeModifiers using addToMap()
val attributeMap: ArrayListMultimap<EntityAttribute, EntityAttributeModifier> = ArrayListMultimap.create()
exampleValidatedAttribute.addToMap(attributeMap)

//if you need the modifier for something else, use attributeModifier()
val myModifier: EntityAttributeModifier = exampleValidatedAttribute.getModifier() 
   //sampleEnd
}

Types

Link copied to clipboard
class Builder @JvmOverloads constructor(attributeId: Identifier, lockAttribute: Boolean = false)

A ValidatedEntityAttribute builder

Link copied to clipboard
data class EntityAttributeInstanceHolder(val attributeId: Identifier, val uuid: UUID, val name: String, val amount: Double, val operation: EntityAttributeModifier.Operation) : EntryHandler<ValidatedEntityAttribute.EntityAttributeInstanceHolder>

A holder of entity attribute and modifier information. This is a class internal to ValidatedEntityAttribute, made public by necessity. In most cases, it's not correct to be directly interacting with this.

Functions

Link copied to clipboard

sets the underlying EntityAttributeInstanceHolder. Consider another method of interaction with this validation before a raw accept() call.

Link copied to clipboard

Attaches a listener to this field. This listener will be called any time the field is written to ("set"). accept, validateAndSet, setAndUpdate and so on will all call the listener.

Link copied to clipboard
fun addToBuilder(builder: AttributeModifiersComponent.Builder, slot: AttributeModifierSlot = AttributeModifierSlot.ANY)

adds the stored Attribute and its modifier to a passed Attribute Component builder

Link copied to clipboard
fun addToComponent(component: AttributeModifiersComponent, slot: AttributeModifierSlot = AttributeModifierSlot.ANY): AttributeModifiersComponent

adds the stored Attribute and its modifier to a passed Attribute Component builder

Link copied to clipboard
fun addToMap(map: Multimap<EntityAttribute, EntityAttributeModifier>)

adds the stored Attribute and its modifier to a passed modifier map.

Link copied to clipboard

Provides a Codec representing the value type of this validation, backed by the validators within, as applicable

Link copied to clipboard

Creates a deep copy of the stored value and returns it

Link copied to clipboard
open fun description(fallback: String? = null): MutableText

The translated Text description from the descriptionKey. Falls back to an empty string so no tooltip is rendered.

Link copied to clipboard
open override fun descriptionKey(): String

translation key of this Translatable's description. the "description" in-game, the descriptions Enchantment Descriptions adds to enchantment tooltips are a good example.

Link copied to clipboard

gets the underlying EntityAttributeInstanceHolder. Consider another method of interaction with this validation before a raw get() call.

Link copied to clipboard

Provides this validations default value

Link copied to clipboard
fun getModifier(): EntityAttributeModifier

builds and returns the EntityAttributeModifier associated with this validation

Link copied to clipboard

Whether this Translatable has a valid description

Link copied to clipboard

Whether this Translatable has a valid translation

Link copied to clipboard

creates a deep copy of this ValidatedEntityAttribute

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun translation(fallback: String?): MutableText

The translated Text name from the translationKey. Falls back to the implementing classes Simple Name (non-translated)

Link copied to clipboard
open override fun translationKey(): String

translation key of this Translatable. the "name" in-game

Link copied to clipboard
fun trySerialize(input: Any?, errorBuilder: MutableList<String>, flags: Byte): TomlElement?
Link copied to clipboard
open override fun trySet(input: Any?)
Link copied to clipboard
open fun update(updateMessage: Text)
Link copied to clipboard
fun updateModifier(new: EntityAttributeModifier)

updates this validation with new EntityAttributeModifier values

Link copied to clipboard

updates this validation with a new double value

Link copied to clipboard

A setter method for the storedValue that first validates the value being set and then stores the post-validation result.

Link copied to clipboard
open fun widgetAndTooltipEntry(choicePredicate: ChoiceValidator<ValidatedEntityAttribute.EntityAttributeInstanceHolder> = ChoiceValidator.any()): ClickableWidget